﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility.SerializeHelp
{
    /// <summary>
    /// btte流帮助类
    /// </summary>
    public static class ByteFlowHelp
    {
        public static byte[] SerializeToByteArray(object obj)
        {
            byte[] buff;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                System.Runtime.Serialization.IFormatter iFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                iFormatter.Serialize(ms, obj);
                buff = ms.GetBuffer();

            }
            return buff;
        }

        public static object ByteToObj(byte[] buff)
        {
            object obj;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(buff))
            {
                System.Runtime.Serialization.IFormatter iFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                obj = iFormatter.Deserialize(ms);

            }
            return obj;
        }
    }
}
